home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / cisco / cisco-expect.shar / ciscoget.exp < prev    next >
Encoding:
Text File  |  1992-08-07  |  1.6 KB  |  70 lines

  1. #!/usr/local/bin/expect -f
  2. #
  3. # Fetch configuration information from the specified cisco router
  4. #
  5. # args: ciscoget router passwd enablepasswd filename
  6. #
  7. set localhost [exec hostname]
  8. set tftpdir /private/tftpboot
  9. set archivedir /n/netmap/HUBS/config
  10.  
  11. set router [index $argv 1]
  12. set password [index $argv 2]
  13. set enablepass [index $argv 3]
  14. set filename [index $argv 4]
  15.  
  16. proc timedout {args} {
  17.     send_user "Expect timed out" $args \n
  18.     exit
  19. }
  20.  
  21. source ciscologin.expect
  22.  
  23. if {[length $argv] < 5} {
  24.     print "Invalid number of arguments\n"
  25.     exit
  26. }
  27.  
  28. spawn telnet $router
  29. login $enablepass
  30. send write network\r
  31.  
  32. expect {*Remote\ host*\?\ } {} \
  33.     timeout        {timedout waiting for Remote host prompt}
  34.  
  35. send ${localhost}
  36.  
  37. expect {*write*?*} {} \
  38.     timeout        {timedout waiting for filename prompt}
  39.  
  40. if {[file ${tftpdir}/${filename} exists]} {
  41.     if {[file ${tftpdir}/${filename}.old exists]} {
  42.         if {[file ${tftpdir}/${filename}.old isfile] == 0} {
  43.               send_user "${tftpdir}/${filename}.old: Not a plain file\n"
  44.               exit 1
  45.         }
  46.         system rm -f  ${tftpdir}/${filename}.old
  47.     }
  48.     system mv -f ${tftpdir}/${filename} ${tftpdir}/${filename}.old
  49. }
  50. system touch ${tftpdir}/${filename}
  51. system chmod 666 ${tftpdir}/${filename}
  52.  
  53.  
  54. send ${filename}\r
  55. expect {*Write\ file*\[confirm\]*} {} \
  56.     timeout        {timed out waiting for confirm}
  57.  
  58. send "Y"
  59. expect    {*Failed*#}    {set failed 1; send_user \nTFTP Write failed\n} \
  60.     {*OK*#}        {set failed 0; send_user \nTFTP Write succeeded\n}
  61.  
  62. send QUIT\r
  63. if {$failed == 0} {
  64.     system cp ${tftpdir}/${filename} ${archivedir}/${filename}
  65.     send_user  "Saved configuration.. "
  66. }
  67. system cleanconfig ${tftpdir}/${filename}
  68. send_user "  cleaned configuration\n"
  69. exit 
  70.